
/*~!
 | @FUNC  项目常量
 | @AUTH  Nobility
 | @DATE  2016-10-17
 | @BRIF  <#brif#>
 */

#ifndef Constant_h
#define Constant_h

#import "AppDelegate.h"
//#import ""

#define APPDelegate ((AppDelegate *)[[UIApplication sharedApplication] delegate])
#define WINDOW [UIApplication sharedApplication].windows[0]
#define KEYWINDOW [Functions topWindow]

#pragma mark - -------------  System Singleton ----------------
#define USERDEFAULT     [NSUserDefaults standardUserDefaults]
#define NOTIFICATION    [NSNotificationCenter defaultCenter]
#define APPLICATION     [UIApplication sharedApplication]
#define APP_DELEGATE    [[UIApplication sharedApplication] delegate]
#define SYSTEM_VERSION  [[[UIDevice currentDevice] systemVersion] floatValue]

#pragma mark - ------------------- XIB --------------------
#define XIB(Class) [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass([Class class]) owner:nil options:nil] firstObject]

#pragma mark - ---------------- Memory ----------------
#define WEAK(weakSelf) __weak typeof(self) weakSelf = self;
#define STRONG(strongSelf,weakSelf) __strong typeof(weakSelf) strongSelf = weakSelf;

#pragma mark - ------------------ NSBundle -------------------
#define BUNDLE      [NSBundle mainBundle]
#define APP_NAME    [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"]
#define APP_VERSION [[[NSBundle mainBundle]infoDictionary] objectForKey:@"CFBundleShortVersionString"]
#define APP_BUILD   [[[NSBundle mainBundle]infoDictionary] objectForKey:@"CFBundleVersion"]

#define BUNDLE_PATH(name, type) [[NSBundle mainBundle] pathForResource:name ofType:type]
#define IMAGE(file) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:file ofType:nil]]

#pragma mark - -------------------- Screen ------------------
#define SCREEN_BOUNDS    [UIScreen mainScreen].bounds
#define SCREEN_WIDTH     [UIScreen mainScreen].bounds.size.width
#define SCREEN_HEIGHT    [UIScreen mainScreen].bounds.size.height
#define KWidth  SCREEN_WIDTH
#define KHeight SCREEN_HEIGHT
#define KBounds SCREEN_BOUNDS

//状态栏高度
#define StatusBar_Height [[UIApplication sharedApplication] statusBarFrame].size.height
//判断是否是iPhone X
#define iPhoneX (StatusBar_Height > 20.f ? YES : NO)
//导航栏高度
#define NavigationBar_Height (iPhoneX?88.f:64.f)
//tabBar高度
#define TabBar_Height (iPhoneX?(49.f+34.f):49.f)
//Home indicator高度
#define HomeIndicator_Height (iPhoneX?34.f:0.f)

#define ViewHeight1 KHeight - NavigationBar_Height
#define ViewHeight2 KHeight - NavigationBar_Height - TabBar_Height
#define ViewHeight3 KHeight - NavigationBar_Height - HomeIndicator_Height

// ----- 适配 ------
#define aufont(a) (a / 360.0 * KWidth)
//字体大小
#pragma mark - ------------------- Font -------------------
#define FONT(size) [UIFont systemFontOfSize:size]

#define HEIGHT(f) f * ([UIScreen mainScreen].bounds.size.width/360.0)

#pragma mark - ------------------- Color -------------------
#define RGB(r,g,b)          [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0]
#define RGBA(r,g,b,a)       [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:(a)/255.0]
#define COLOR_CLEAR         [UIColor clearColor]
// rgb颜色转换（16进制->10进制）
#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]

#pragma mark - ------------------- 字体 -------------------
#define FONT(size) [UIFont systemFontOfSize:size]
#define R_Font(a) [UIFont fontWithName:@"PingFangSc-Regular" size:aufont(a)]
#define M_Font(a) [UIFont fontWithName:@"PingFangSc-Medium" size:aufont(a)]
#define B_Font(a) [UIFont fontWithName:@"PingFangSc-Bold" size:aufont(a)]

#pragma mark - -------------------- Log --------------------
#if DEBUG
#define NSLog(FORMAT, ...) fprintf(stderr,"-------------------------- [NSLog] -------------------------- \n[D]:%s\n[T]:%s\n[F]:%s\n[M]:%s\n[L]:%d\n[C]:%s\n", __DATE__, __TIME__, __FILE__,__FUNCTION__, __LINE__, [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);
#else
#define NSLog(FORMAT, ...) nil
#endif

#if DEBUG
#define HRLog(FORMAT, ...) fprintf(stderr,"-------------------------- [NSLog] -------------------------- \n%s\n",[[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);
#else
#define HRLog(FORMAT, ...) nil
#endif

#pragma mark - ------------------- 字符串 -------------------
#define SF(...) [NSString stringWithFormat:__VA_ARGS__]
#define NIL(string) (string == nil || (NSNull *)string == [NSNull null] || [string isEqualToString:@""])
#define LOCAL_STRING(x, ...) NSLocalizedString(x, nil)

#pragma mark - ------------------- 多线程 -------------------
#define GCD_G_Q dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)
#define GCD_M_Q dispatch_get_main_queue()
#define GCD_AS_G_Q(block) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), block); // 异步执行全局队列
#define GCD_AS_M_Q(block) dispatch_async(dispatch_get_main_queue(),block);  // 异步执行主队列
#define GCD_DELAY(time, block) dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(time * NSEC_PER_SEC)), dispatch_queue_create("custom", DISPATCH_QUEUE_CONCURRENT), block); // 延时执行
#define GCD_ONCE(block) static dispatch_once_t onceToken; dispatch_once(&onceToken, block); // 只执行一次

#pragma mark - ------------------- Language -------------------
#define LANGUAGE ([[NSLocale preferredLanguages] objectAtIndex:0]) // 本地语言

#pragma mark - ------------------- Radian && Degrees -------------------
#define RADIAN(degrees) (M_PI * (degrees) / 180.0) // 角度转弧度
#define DEGREES(radian) (radian*180.0)/(M_PI) // 弧度转角度

// View 圆角
#define ViewRadius(View, Radius)\
\
[View.layer setCornerRadius:(Radius)];\
[View.layer setMasksToBounds:YES]

// View 圆角和加边框
#define ViewBorderRadius(View, Radius, Width, Color)\
\
[View.layer setCornerRadius:(Radius)];\
[View.layer setMasksToBounds:YES];\
[View.layer setBorderWidth:(Width)];\
[View.layer setBorderColor:[Color CGColor]]

#define IMG(name) [UIImage imageNamed:name]
#define DefalutImage IMG(@"defalutImg")

/// 判断字符串是否为空或者为空字符串 YES:空的
#define STR_Is_NullOrEmpty(str) (str == nil || [str isEqualToString:@""] || [str isEqual:[NSNull null]])

#define UID  [[NSUserDefaults standardUserDefaults] objectForKey:KEY_user_id]
static NSString *const NET_NOT_WORK = @"网络断开连接，请检查网络";
static NSString *const ERROR_MESSAGE = @"网络异常";
static NSString *const NET_FAIL = @"网络请求失败,请稍后再试";

//没有更多数据提示
#define NoMoreDataHit @"无更多数据"

//不支持表情输入提示
#define NotSupportFaceInput @"还不支持表情输入哦"

/// 存储用信息的key
static NSString *const UserInfoKEY = @"UserInfoKEY";
/// 储存 token 的key
static NSString *const TokenKEY = @"token";
/// 储存 mobile 的key
static NSString *const MobileKEY = @"mobile";
/// 储存 first_login 的 key
static NSString *const First_loginKEY = @"first_login";
/// 搜索社团和大学的历史记录Key
static NSString *const History1 = @"UniversityClubHistory";


// MARK: -- 通知

/// 正在请求
#define NetWorkLoadingNotification @"NetWorkLoadingNotification"
/// 请求结束
#define NetWorkLoadingEndNotification @"NetWorkLoadingEndNotification"

/// 我的优惠券通知(编辑)
#define MyCouponEditNotification @"RBKMyCouponContainerFinishNotification"

/// 我的订单(倒计时)
#define MyOrderTimeDownNotification @"RBKMyOrderTimeDownNotification"

/// BaseSegContainerVC 返回时发送通知
#define SegContainerVCBackNotification @"BaseSegContainerVCBackNotification"
#define CancelLandingNotification @"CancelLanding"//取消登陆
#endif /* ProjectCommon_h */
